package algorithm;

public class TreeUtil {

    /*
    *          1
    *      2      3
    *   4    5  6    7
    * */
    public static TreeNode build(){
        TreeNode node4 = new TreeNode(4);
        TreeNode node5 = new TreeNode(5);
        TreeNode node2 = new TreeNode(2,node4,node5);
        TreeNode node6 = new TreeNode(6);
        TreeNode node7 = new TreeNode(7);
        TreeNode node3 = new TreeNode(3,node6,node7);
        return new TreeNode(1, node2, node3);
    }

    /*
     *          5
     *      3      7
     *    1   4  6    8
     * */
    public static TreeNode buildSearchTree(){
        TreeNode node1 = new TreeNode(1);
        TreeNode node4 = new TreeNode(4);
        TreeNode node3 = new TreeNode(3,node1,node4);
        TreeNode node6 = new TreeNode(6);
        TreeNode node8 = new TreeNode(8);
        TreeNode node7 = new TreeNode(7,node6,node8);
        return new TreeNode(5, node3, node7);
    }

    /*
     *          5
     *       3      7
     *    1    4
     * */
    public static TreeNode buildTotalTree(){
        TreeNode node1 = new TreeNode(1);
        TreeNode node4 = new TreeNode(4);
        TreeNode node3 = new TreeNode(3,node1,node4);
        TreeNode node7 = new TreeNode(7);
        return new TreeNode(5, node3, node7);
    }

    /* null 6 null 2 null null
     *          5
     *       3      7
     *    1    4
     *  2    6
     * */
    public static TreeNode buildNoTotalTree(){
        TreeNode node2 = new TreeNode(2);
        TreeNode node6 = new TreeNode(6);
        TreeNode node1 = new TreeNode(1,node2,null);
        TreeNode node4 = new TreeNode(4,node6,null);
        TreeNode node3= new TreeNode(3,node1,node4);
        TreeNode node7 = new TreeNode(7);
        return new TreeNode(5, node3, node7);
    }

    /*
     *          5
     *       3      7
     *    1    4
     * */
    public static TreeNode buildNoCompleteTree(){
        TreeNode node1 = new TreeNode(1);
        TreeNode node4 = new TreeNode(4);
        TreeNode node3= new TreeNode(3,node1,node4);
        TreeNode node7 = new TreeNode(7);
        return new TreeNode(5, node3, node7);
    }

    /*
     *          5
     *       3      3
     *    1    4  4   1
     * */
    public static TreeNode buildSymmetricalTree(){
        TreeNode node1 = new TreeNode(1);
        TreeNode node4 = new TreeNode(4);
        TreeNode node3= new TreeNode(3,node1,node4);
        TreeNode nodeNew3 = new TreeNode(3,node4,node1);
        return new TreeNode(5, node3, nodeNew3);
    }
}
